
#define SIZE 1000


int getCol(int map[SIZE][SIZE], int x, int y)
{
	while(y < SIZE - 1 && map[x][y + 1] == 1)
	{	
		y = y + 1;
		if( map[x][y + 1] == 1 && map[x - 1][y] == 1 ||(map[x][y+1]&& map[x + 1][y] == 1))
			return 0;
	}
	return y;
}

int getRow(int map[SIZE][SIZE], int x, int y)
{
	while(x < SIZE - 1 && map[x + 1][y] == 1)
	{
		x = x + 1;
		if(( map[x + 1][y] == 1 && map[x][y - 1] == 1 )||(map[x+1][y]==1 && map[x][y + 1] == 1) )
			return 0;
	}
	return x;
}

int test_main(int map[SIZE][SIZE])
{
	int count = 0;
	int i = 1;
	int j = 1;

	while(i < SIZE)
	{
		while(j < SIZE)
		{
			if(map[i][j] == 1)
			{
				int w = getCol(map,i,j);
				int h = getRow(map,i,j);
				int w1 = getCol(map,h, j);
				int h1 = getRow(map,i,w);
				if(h==h1&&w==w1&&h-i>=2&&w-j>=2)
					count = count + 1;
			}
			j = j + 1;
		}
		i = i + 1;
		j = 0;
	}

	return count;
}



